<?php
require 'model-db-connection/config.php';
$config = require 'model-db-connection/qrc_conf.properties.php';
?>
<div class="innerLR" style="width: 1000px">
    <a href="index-mainpage.php">Main Page</a> -> <span id="link_to_teamBuilder"></span><span id="link_to_project_order"></span><br/>
</div>
<div class="innerLR" style="width:1000px">
    <div class="widget">
        <div class="widget-head">
            <h4 class="heading">Search PO/Inspection (ค้นหา PO/ใบตรวจรับงาน)</h4>
            <div class="clearfix"></div>
        </div>
        <div class="widget-body innerAll inner-2x">
            <fieldset>
                <legend>Search Type (ประเภทการค้นหา)</legend>
                <table width="100%">
                    <tr>
                        <td><select id="search_builder_change" class="form-control" name="search_builder_change">
                                <option value="0"></option>
                                <option value="1">Search PO (ค้นหา PO)</option>
                                <option value="2">Search Inspection (ค้นหา ใบตรวจรับงาน)</option>
                            </select></td>
                    </tr>
                </table>
            </fieldset>

            <br/>
            <div id="search_po">
                <table width="100%">
                    <tr>
                        <td align="right" style="width:250px">Project Name (ชื่อโครงการ):</td>
                        <td align="left" style="width:250px">
                            <!--<input type="text" class="form-control" id="team_code_search">-->
                            <select class="form-control" id="po_project_name_search" name="po_project_name_search">
                                <option value="0"></option>
                                <?php
                                $sqlSelectMemType = "SELECT * FROM QRC_PROJECT;";
                                $resultSets = mysql_query($sqlSelectMemType);
                                while ($row = mysql_fetch_array($resultSets)) {
                                    echo '<option value="' . $row['project_code'] . '">' . $row['project_name'] . '</option>';
                                }
                                ?>
                            </select>
                        </td>
                        <td align="right" style="width:250px">Project Code (หมายเลขโครงการ):</td>
                        <td align="left" style="width:250px"><input type="text" class="form-control" id="po_project_code_search"></td>
                    </tr>
                    <tr>
                        <td align="right" style="width:250px">Document No. (เลขที่):</td>
                        <td align="left" style="width:250px">
                            <input type="text" class="form-control" id="po_document_no_search">
                        </td>
                        <td align="right" style="width:250px">PO No. (เลขที่ใบสั่งจ้าง):</td>
                        <td align="left" style="width:250px"><input type="text" class="form-control" id="po_po_no_search"></td>
                    </tr>
                    <tr>
                        <td align="right" style="width:250px">PO Owner (เจ้าของ PO):</td>
                        <td align="left" style="width:250px">
                            <input type="text" class="form-control" id="po_owner_search">
                        </td>
                        <td align="right" style="width:250px">PO Sender (จนท. PO):</td>
                        <td align="left" style="width:250px"><input type="text" class="form-control" id="po_sender_search"></td>
                    </tr>
                    <tr>
                        <td align="right" style="width:250px">Issue Date (วันที่):</td>
                        <td align="left" style="width:250px"><input type="text" class="form-control date_selecter" id="po_issue_date_search"></td>
                        <td align="right" style="width:250px">Order Type (ประเภทงาน):</td>
                        <td align="left" style="width:250px">
                            <select class="form-control" id="po_order_type_search" name="po_order_type_search">
                                <option value="0"></option>
                                <?php
                                $sqlSelectMemType = "SELECT * FROM QRC_TYPE_OF_SERVICE;";
                                $resultSets = mysql_query($sqlSelectMemType);
                                while ($row = mysql_fetch_array($resultSets)) {
                                    echo '<option value="' . $row['service_id'] . '">' . $row['service_name'] . '</option>';
                                }
                                ?>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td style="width:250px;" colspan="4" align="center"><span style="color: red;">*ถ้าต้องการค้นหาทั้งหมด กรุณาเว้นช่องว่าง</span></td>
                    </tr>
                    <tr>
                        <td align="right" style="width:250px" colspan="2"><button class = "btn btn-primary" style="margin-left: 5px" id="po_search_btn">Search (ค้นหา)</button></td>
                        <td align="left" style="width:250px" colspan="2"><button class = "btn btn-primary" style="margin-left: 5px" id="po_reset_btn">Reset (รีเซต)</button></td>
                    </tr>
                </table>
            </div>


            <div id="search_inspection">
                <table width="100%">
                    <tr>
                        <td align="right" style="width:250px">Project Name (ชื่อโครงการ):</td>
                        <td align="left" style="width:250px">
                            <!--<input type="text" class="form-control" id="team_code_search">-->
                            <select class="form-control" id="po_project_name_search" name="inspection_project_name_search">
                                <option value=""></option>
                                <?php
                                $sqlSelectMemType = "SELECT * FROM QRC_PROJECT;";
                                $resultSets = mysql_query($sqlSelectMemType);
                                while ($row = mysql_fetch_array($resultSets)) {
                                    echo '<option value="' . $row['project_code'] . '">' . $row['project_name'] . '</option>';
                                }
                                ?>
                            </select>
                        </td>
                        <td align="right" style="width:250px">Project Code (หมายเลขโครงการ):</td>
                        <td align="left" style="width:250px"><input type="text" class="form-control" id="inspection_project_code_search"></td>
                    </tr>
                    <tr>
                        <td align="right" style="width:250px">Document No. (เลขที่):</td>
                        <td align="left" style="width:250px">
                            <input type="text" class="form-control" id="inspection_document_no_search">
                        </td>
                        <td align="right" style="width:250px">Inspection No. (เลขที่ใบสั่งจ้าง):</td>
                        <td align="left" style="width:250px"><input type="text" class="form-control" id="inspection_no_search"></td>
                    </tr>
                    <tr>
                        <td align="right" style="width:250px">Inspection Date (วันที่):</td>
                        <td align="left" style="width:250px">
                            <input type="text" class="form-control" id="inspection_date_search">
                        </td>
                        <td align="right" style="width:250px">Order Type (ประเภทงาน):</td>
                        <td align="left" style="width:250px">
                            <select class="form-control" id="po_order_type_search" name="inspection_order_type_search">
                                <option value=""></option>
                                <?php
                                $sqlSelectMemType = "SELECT * FROM QRC_TYPE_OF_SERVICE;";
                                $resultSets = mysql_query($sqlSelectMemType);
                                while ($row = mysql_fetch_array($resultSets)) {
                                    echo '<option value="' . $row['service_id'] . '">' . $row['service_name'] . '</option>';
                                }
                                ?>
                            </select>
                        </td>   
                    </tr>
                    <tr>
                        <td align="right" style="width:250px">Plan (แบบบ้าน):</td>
                        <td align="left" style="width:250px">
                            <input type="text" class="form-control" id="inspection_home_plan_search">
                        </td>
                        <td align="right" style="width:250px">Plot (แปลงบ้าน):</td>
                        <td align="left" style="width:250px"><input type="text" class="form-control" id="inspection_home_plot_search"></td>
                    </tr>
                    <tr>
                        <td align="right" style="width:250px">PO No. (เลขที่ใบสั่งจ้าง):</td>
                        <td align="left" style="width:250px"><input type="text" class="form-control" id="inspection_po_no_search"></td>

                        <td align="right" style="width:250px">PO Issue Date (วันที่):</td>
                        <td align="left" style="width:250px"><input type="text" class="form-control" id="inspection_po_issue_date_search"></td>
                    </tr>
                    <tr>
                        <td align="right" style="width:250px">Quantity (จำนวน):</td>
                        <td align="left" style="width:250px"><input type="text" class="form-control" id="inspection_quantity_search"></td>
                        <td align="right" style="width:250px">Plan Size (ขนาด ตร.ม.):</td>
                        <td align="left" style="width:250px"><input type="text" class="form-control" id="inspection_home_plot_search"></td>
                    </tr>
                    <tr>
                        <td align="right" style="width:250px">Upload Copy File (แนบไฟล์ต้นฉบับ):</td>
                        <td align="left" style="width:250px"><input type="file" class="form-control" id="inspection_attached_search"></td>
                        <td align="right" style="width:250px"></td>
                        <td align="left" style="width:250px"></td>
                    </tr>
                    <tr>
                        <td align="right" style="width:250px">Project Manager (ผู้จัดการโครงการ):</td>
                        <td align="left" style="width:250px"><input type="text" class="form-control" id="inspection_project_manager_search"></td>
                        <td align="right" style="width:250px">Project Foreman (ผู้ควบคุมงานของโครงการ):</td>
                        <td align="left" style="width:250px"><input type="text" class="form-control" id="inspection_project_foreman_search"></td>
                    </tr>
                    <tr>
                        <td align="right" style="width:250px">Supervisor Control (ผู้ควบคุมงานของลูกค้า):</td>
                        <td align="left" style="width:250px"><input type="text" class="form-control" id="inspection_project_supervisor_search"></td>
                        <td align="right" style="width:250px"></td>
                        <td align="left" style="width:250px"></td>
                    </tr>
                    <tr>
                        <td align="right" style="width:250px">Remark:</td>
                        <td align="left" colspan="3"><input type="text" class="form-control" id="inspection_remark_search"></td>

                    </tr>
                    <tr>
                        <td style="width:250px;" colspan="4" align="center"><span style="color: red;">*ถ้าต้องการค้นหาทั้งหมด กรุณาเว้นช่องว่าง</span></td>
                    </tr>
                    <tr>
                        <td align="right" style="width:250px" colspan="2"><button class = "btn btn-primary" style="margin-left: 5px" id="team_builder_search_btn">Search (ค้นหา)</button></td>
                        <td align="left" style="width:250px" colspan="2"><button class = "btn btn-primary" style="margin-left: 5px" id="team_builder_reset_btn">Reset (รีเซต)</button></td>
                    </tr>
                </table>
            </div>

        </div>
    </div>
</div>
<div class="loader"></div>
<div class="innerLR" style="width:1200px">

    <div id="load_po"></div>
    <div id="load_inspection"></div>

</div>
<script src="assets/components/plugins/preload/pace/pace.min.js?v=v1.0.2&sv=v0.0.1"></script>
<script src="assets/components/plugins/preload/pace/preload.pace.init.js?v=v1.0.2&sv=v0.0.1"></script>
<script src="assets/components/common/forms/elements/multiselect/assets/lib/js/jquery.multi-select.js?v=v1.0.2&sv=v0.0.1"></script>
<script src="assets/components/common/forms/elements/multiselect/assets/custom/js/multiselect.init.js?v=v1.0.2&sv=v0.0.1"></script>
<script src="assets/components/common/forms/elements/select2/assets/lib/js/select2.js?v=v1.0.2&sv=v0.0.1"></script>
<script src="assets/components/common/forms/elements/select2/assets/custom/js/select2.init.js?v=v1.0.2&sv=v0.0.1"></script>


<script type="text/javascript">
    $(window).load(function() {
        $(".loader").fadeOut("slow");
    });
    var createOrEditState = "Create";
    $(document).ready(function() {
        $(".date_selecter").datepicker();
        $("#search_po, #search_inspection").hide();
        $('#search_builder_change').change(function() {
            var value = $(this).val();
            if (value == 0) {
                $("#search_po, #search_inspection").hide();
            }
            if (value == 1) {
                $("#search_po").show();
                $("#search_inspection").hide();
                $("#load_member").empty();
            }
            if (value == 2) {
                $("#search_po").hide();
                $("#search_inspection").show();
                $("#load_team").empty();
            }
        });
        $("#link_to_teamBuilder").append("PO/Inspection (PO/ใบตรวจรับงาน)");
        $("#po_search_btn").click(function() {
            var project_id = $("#po_project_name_search").val();
            var project_code = $("#po_project_code_search").val();
            var document_no = $("#po_document_no_search").val();
            var po_no = $("#po_po_no_search").val();
            var po_owner = $("#po_owner_search").val();
            var po_sender = $("#po_sender_search").val();
            var po_issue_date = $("#po_issue_date_search").val();
            var po_order_type = $("#po_order_type_search").val();
            var data = "project_id=" + project_id +
                    "&project_code=" + project_code +
                    "&document_no=" + document_no +
                    "&po_no=" + po_no +
                    "&po_owner=" + po_owner +
                    "&po_sender=" + po_sender +
                    "&po_issue_date=" + po_issue_date +
                    "&po_order_type=" + po_order_type;
            blockPage();
            if (project_id !== 0 ||
                    $.trim(project_code).length !== 0 ||
                    $.trim(document_no).length !== 0 ||
                    $.trim(po_no).length !== 0 ||
                    $.trim(po_owner).length !== 0 ||
                    $.trim(po_sender).length !== 0 ||
                    $.trim(po_issue_date).length !== 0 ||
                    po_order_type !== 0) {
                $("#load_po").load("PoMainPage.php?searchCondition=Condition&" + data, function() {
                    $.unblockUI();
                });
            } else {
                $("#load_po").load("PoMainPage.php?searchCondition=All", function() {
                    $.unblockUI();
                });
            }

        });
        $("#po_reset_btn").click(function() {
            $("#test-load").empty();
            $("#test-load").load("PoInspectionMainPage.php", function() {
                $.unblockUI();
                $('#search_builder_change').val("1");
                $("#search_po").show();
                $("#search_inspection").hide();
            });
        })
    });
    function blockPage() {
        $.blockUI({message: 'Operation in progress...', css: {
                border: 'none',
                padding: '15px',
                backgroundColor: '#000',
                '-webkit-border-radius': '10px',
                '-moz-border-radius': '10px',
                opacity: .5,
                color: '#fff'
            }});
    }
</script>
<style type="text/css">
    .loader {
        position: fixed;
        left: 0px;
        top: 0px;
        width: 100%;
        height: 100%;
        z-index: 9999;
        background: url('image/page-loader.gif') 50% 50% no-repeat rgb(249,249,249);

    }
</style>